/**
 * @file spi_bsp.h
 * @author  xiaowine (xiaowine@sina.cn)
 * @brief
 * @version 01.00
 * @date    2021-07-07
 *
 * @copyright Copyright (c) {2020}  xiaowine
 *
 * @par ????:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2021-07-07 <td>1.0     <td>wangh     <td>??
 * </table>
 * ******************************************************************
 * *                   .::::
 * *                 .::::::::
 * *                ::::::::::
 * *             ..:::::::::::
 * *          '::::::::::::
 * *            .:::::::::
 * *       '::::::::::::::..        ????,????
 * *            ..::::::::::::.     ????,???bug
 * *          ``:::::::::::::::
 * *           ::::``:::::::::'        .:::
 * *          ::::'   ':::::'       .::::::::
 * *        .::::'      ::::     .:::::::'::::
 * *       .:::'       :::::  .:::::::::' ':::::
 * *      .::'        :::::.:::::::::'      ':::::
 * *     .::'         ::::::::::::::'         ``::::
 * * ...:::           ::::::::::::'              ``::
 * *```` ':.          ':::::::::'                  ::::.
 * *                   '.:::::'                    ':'````.
 * ******************************************************************
 */

#ifndef __SPI_BSP_H_
#define __SPI_BSP_H_

/* Private includes ----------------------------------------------------------*/
#include "stm32f10x.h"

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/
#define BufferSize 128
#define transSize  128
/* Public define ------------------------------------------------------------*/
#define SPI1_INDEX 0
#define SPI2_INDEX 1

#define SPI1_CS(x) GPIO_WriteBit(GPIOA, GPIO_Pin_4, (x))
#define SPI2_CS(x) GPIO_WriteBit(GPIOB, GPIO_Pin_12, (x))

// #define SPI_USING_DMA
/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/
#ifdef SPI_USING_DMA
extern volatile uint8_t spiDmaRxBuffer[2][BufferSize];
extern volatile uint8_t spiDmaTxBuffer[2][BufferSize];
#endif
/* Public variables ---------------------------------------------------------*/
#ifdef SPI_USING_DMA
void spi_initDMA(SPI_TypeDef *SPIx);
void spiStartDMA(SPI_TypeDef *SPIx);
void spiSend(SPI_TypeDef *SPIx);
#endif
/* Private function prototypes -----------------------------------------------*/
int8_t SPIx_ReadWriteByte(SPI_TypeDef *SPIx, uint8_t TxData);
void   SPI_BUS_Init(void);
void   SPI_CS_H(void);
void   SPI_CS_L(void);
/* Private user code ---------------------------------------------------------*/

#endif /*__SPI_BSP_H_*/
